﻿<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">

    <!-- Resource dictionary entries should be defined here. -->
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Colors.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="TreeViewItemStyle" TargetType="{x:Type TreeViewItem}">
		<Setter Property="Padding" Value="3" />
		<Setter Property="HorizontalContentAlignment" Value="Left" />
		<Setter Property="VerticalContentAlignment" Value="Top" />
		<Setter Property="Background" Value="Transparent" />
		<Setter Property="Foreground">
			<Setter.Value>
				<SolidColorBrush Color="{StaticResource Application_TreeviewItem_Foreground}"/>
			</Setter.Value>
		</Setter>
		<Setter Property="IsTabStop" Value="True" />
		<Setter Property="Margin" Value="0,1,0,0" />
        <Setter Property="Template" Value="{DynamicResource {ComponentResourceKey ResourceId=TreeViewItemTemplate, TypeInTargetAssembly={x:Type TreeViewItem}}}"/>
		<Setter Property="MinHeight" Value="20"/>
		<Setter Property="Height" Value="Auto"/>
	</Style>

    <ControlTemplate x:Key="{ComponentResourceKey ResourceId=TreeViewItemTemplate, TypeInTargetAssembly={x:Type TreeViewItem}}" TargetType="{x:Type TreeViewItem}">
        <Grid Width="{TemplateBinding Width}">
    		<VisualStateManager.VisualStateGroups>
    			<VisualStateGroup x:Name="CommonStates">
    				<VisualStateGroup.Transitions>
    					<VisualTransition From="Normal" GeneratedDuration="0:0:0.3" To="MouseOver"/>
    					<VisualTransition From="MouseOver" GeneratedDuration="0:0:0.3" To="Normal"/>
    				</VisualStateGroup.Transitions>
    				<VisualState x:Name="Normal"/>
    				<VisualState x:Name="MouseOver">
    					<Storyboard>
    						<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="bg">
    							<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_TreeviewItem_Background_Move}"/>
    						</ColorAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    				<VisualState x:Name="Disabled">
    					<Storyboard>
    						<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)">
    							<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_TreeviewItem_Foreground_Disabled}"/>
    						</ColorAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    			</VisualStateGroup>
    			<VisualStateGroup x:Name="FocusStates">
    				<VisualState x:Name="Focused"/>
    				<VisualState x:Name="Unfocused"/>
    			</VisualStateGroup>
    			<VisualStateGroup x:Name="SelectionStates">
    				<VisualStateGroup.Transitions>
    					<VisualTransition From="Selected" GeneratedDuration="0:0:0.3" To="SelectedInactive"/>
    					<VisualTransition GeneratedDuration="0:0:0.2" To="Selected"/>
    					<VisualTransition From="Selected" GeneratedDuration="0:0:0.2"/>
    				</VisualStateGroup.Transitions>
    				<VisualState x:Name="Selected">
    					<Storyboard>
    						<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="SelectionFill">
    							<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
    						</DoubleAnimationUsingKeyFrames>
    						<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="SelectionBorder">
    							<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
    						</DoubleAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    				<VisualState x:Name="Unselected"/>
    				<VisualState x:Name="SelectedInactive">
    					<Storyboard>
    						<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="SelectionBorder">
    							<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
    						</DoubleAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    			</VisualStateGroup>
    			<VisualStateGroup x:Name="ExpansionStates">
    				<VisualStateGroup.Transitions>
    					<VisualTransition From="Collapsed" GeneratedDuration="0:0:0.4" To="Expanded">
    						<Storyboard>
    							<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ItemsHost">
    								<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
    							</ObjectAnimationUsingKeyFrames>
    						</Storyboard>
    					</VisualTransition>
    					<VisualTransition From="Expanded" GeneratedDuration="0:0:0.4" To="Collapsed">
    						<Storyboard>
    							<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ItemsHost">
    								<DiscreteObjectKeyFrame KeyTime="0:0:0.4" Value="{x:Static Visibility.Collapsed}"/>
    							</ObjectAnimationUsingKeyFrames>
    						</Storyboard>
    					</VisualTransition>
    				</VisualStateGroup.Transitions>
    				<VisualState x:Name="Expanded">
    					<Storyboard>
    						<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="ItemsHost">
    							<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
    						</DoubleAnimationUsingKeyFrames>
    						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ItemsHost">
    							<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/>
    						</ObjectAnimationUsingKeyFrames>
    						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.VerticalAlignment)" Storyboard.TargetName="Header">
    							<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static VerticalAlignment.Stretch}"/>
    						</ObjectAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    				<VisualState x:Name="Collapsed"/>
    			</VisualStateGroup>
    			<VisualStateGroup x:Name="HasItemsStates">
    				<VisualState x:Name="HasItems"/>
    				<VisualState x:Name="NoItems">
    					<Storyboard>
    						<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="ExpanderButton">
    							<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Hidden}"/>
    						</ObjectAnimationUsingKeyFrames>
    					</Storyboard>
    				</VisualState>
    			</VisualStateGroup>
    			<VisualStateGroup x:Name="ValidationStates">
    				<VisualState x:Name="Valid"/>
    				<VisualState x:Name="InvalidFocused"/>
    				<VisualState x:Name="InvalidUnfocused"/>
    			</VisualStateGroup>
    		</VisualStateManager.VisualStateGroups>

            <Grid.RowDefinitions>
            	<RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="15" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            
            <Rectangle x:Name="bg" Grid.Column="0" Grid.ColumnSpan="3" Opacity="1" StrokeThickness="0" IsHitTestVisible="False" RadiusX="0" RadiusY="0" Stroke="{x:Null}">
    			<Rectangle.Fill>
    				<SolidColorBrush Color="{StaticResource Application_TreeviewItem_Background}" />
    			</Rectangle.Fill>
    		</Rectangle>
    		<Rectangle x:Name="SelectionFill" Grid.Column="0" Grid.ColumnSpan="3" RadiusX="0" Opacity="0">
    			<Rectangle.Fill>
    				<SolidColorBrush Color="{StaticResource Application_TreeviewItem_Background_Selection}" />
    			</Rectangle.Fill>
			</Rectangle>
    		<Rectangle x:Name="SelectionBorder" Grid.Column="0" Grid.ColumnSpan="3" Opacity="0" StrokeThickness="1" IsHitTestVisible="False">
    			<Rectangle.Stroke>
    				<SolidColorBrush Color="{StaticResource Application_TreeviewItem_BorderBrush_Selection}" />
    			</Rectangle.Stroke>
    		</Rectangle>
    		<ToggleButton x:Name="ExpanderButton" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
    			          IsTabStop="False" Template="{DynamicResource TreeViewItemExpanderButtonTemplate}"
                          IsChecked="{Binding IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
                          ClickMode="Press"/>
    		<ContentPresenter x:Name="Header" Grid.Column="1"
			    			  Cursor="{TemplateBinding Cursor}" Content="{TemplateBinding Header}" 
			    			  ContentTemplate="{TemplateBinding HeaderTemplate}" 
			    			  HorizontalAlignment="Left" Margin="{TemplateBinding Padding}" IsHitTestVisible="False" />
    		<ItemsPresenter x:Name="ItemsHost" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" Visibility="Collapsed" Opacity="0" />
    	</Grid>
    </ControlTemplate>

    <ControlTemplate x:Key="TreeViewItemExpanderButtonTemplate" TargetType="{x:Type ToggleButton}">
        <Grid x:Name="Root" Background="Transparent">
            <VisualStateManager.VisualStateGroups>
                <VisualStateGroup x:Name="CommonStates">
            		<VisualStateGroup.Transitions>
            			<VisualTransition From="MouseOver" GeneratedDuration="0:0:0.3" To="Normal"/>
            			<VisualTransition From="Normal" GeneratedDuration="0:0:0.3" To="MouseOver"/>
            		</VisualStateGroup.Transitions>
            		<VisualState x:Name="Normal" />
            		<VisualState x:Name="MouseOver">
            			<Storyboard>
            				<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="UncheckedVisual">
            					<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_Control_Background_Move}"/>
            				</ColorAnimationUsingKeyFrames>
            				<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="CheckedVisual">
            					<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_Control_Background_Move}"/>
            				</ColorAnimationUsingKeyFrames>
            			</Storyboard>
            		</VisualState>
            		<VisualState x:Name="Disabled">
            			<Storyboard>
            				<DoubleAnimation Storyboard.TargetName="Root" Storyboard.TargetProperty="Opacity" To=".7" Duration="0" />
            			</Storyboard>
            		</VisualState>
            		<VisualState x:Name="Pressed">
            			<Storyboard>
            				<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="UncheckedVisual">
            					<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_Control_Background_Move}"/>
            				</ColorAnimationUsingKeyFrames>
            				<ColorAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="CheckedVisual">
            					<EasingColorKeyFrame KeyTime="0" Value="{StaticResource Application_Control_Background_Move}"/>
            				</ColorAnimationUsingKeyFrames>
            			</Storyboard>
            		</VisualState>
            	</VisualStateGroup>
                <VisualStateGroup x:Name="CheckStates">
                	<VisualStateGroup.Transitions>
                		<VisualTransition From="Checked" GeneratedDuration="0:0:0.4" To="Unchecked"/>
                		<VisualTransition From="Unchecked" GeneratedDuration="0:0:0.4" To="Checked"/>
                	</VisualStateGroup.Transitions>
                	<VisualState x:Name="Unchecked" />
                	<VisualState x:Name="Checked">
                		<Storyboard>
                			<DoubleAnimation Storyboard.TargetName="UncheckedVisual" Storyboard.TargetProperty="Opacity" To="0" Duration="0" />
                			<DoubleAnimation Storyboard.TargetName="CheckedVisual" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                		</Storyboard>
                	</VisualState>
                	<VisualState x:Name="Indeterminate"/>
                </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Grid HorizontalAlignment="Right" Margin="2 2 5 2">
                <Path x:Name="UncheckedVisual" Width="6" Height="9" VerticalAlignment="Center" HorizontalAlignment="Right" Data="M 0,0 L 0,9 L 5,4.5 Z" StrokeThickness="1" StrokeLineJoin="Miter" Stroke="{x:Null}">
                	<Path.Fill>
                		<SolidColorBrush Color="{StaticResource Application_Control_Background}"/>
                	</Path.Fill>
                </Path>
                <Path x:Name="CheckedVisual" Opacity="0" Width="6" Height="6" VerticalAlignment="Center" HorizontalAlignment="Center" Data="M 6,0 L 6,6 L 0,6 Z" StrokeLineJoin="Miter" >
                	<Path.Fill>
                		<SolidColorBrush Color="{StaticResource Application_Control_Background}"/>
                	</Path.Fill>
                </Path>
            </Grid>
        </Grid>
    </ControlTemplate>
</ResourceDictionary>